/*
倒计时节点逻辑处理
*/
cc.Class({
    extends: cc.Component,

    properties: {
        timeNumLabel:{
            default:null,
            type:cc.Label
        },
    },

    // use this for initialization
    onLoad:function () {
    },

    onInit: function(){
        this.curTimeNum = 0;
        this.timeNumMax = 0;
        this.timeUpdate = -1;
    },

    setTime:function(newTimeNum){
        this.timeNumMax = newTimeNum;
        this.curTimeNum = newTimeNum;
        this.timeNumLabel.string = this.curTimeNum;
        // if(this.timeUpdate != -1)
            // this.unschedule(this.timeUpdate);
        window.protectedUnschedule(this,this.timeUpdate);
        if(this.curTimeNum <=3)
        {
            window.DKTools.audioEG.playEffect("tips_timer10s");
        }
        else
        {
            window.DKTools.audioEG.stopTimerEffect();
        }

        this.timeUpdate = function () {
            this.curTimeNum--;
            this.timeNumLabel.string = this.curTimeNum;
            if(this.curTimeNum <=3 )
            {
                window.DKTools.audioEG.playEffect("tips_timer10s");
            }
            if (this.curTimeNum == 0) 
            {
                this.hideTimer();
                // this.unschedule(this.timeUpdate);
                window.protectedUnschedule(this,this.timeUpdate);
                this.timeUpdate = -1;
            }
        };
        this.schedule(this.timeUpdate, 1);
        this.showTimer();
    },

    showTimer:function(){
        this.node.active = true;
    },

    hideTimer:function(){
        this.node.active = false;
        window.DKTools.audioEG.stopTimerEffect();
    },
});
